#
# @lc app=leetcode.cn id=121 lang=python3
#
# [121] 买卖股票的最佳时机
#

# @lc code=start
from typing import List

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        #记录 i之前位置的最低价格 动态更新最大利润
        ans,min_price,n= 0,prices[0],len(prices)
        for i in range(1,n):
            ans = max(ans,prices[i] - min_price)
            min_price = min(min_price,prices[i])
        return ans
# @lc code=end

